<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%@ include file="function.jsp"%>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>医院新闻管理</title>
    <link  href="../images/favicon.ico?cache=<%=Math.random()%>" rel="shortcut icon" type="image/x-icon">
    <link rel="stylesheet" href="../css/public.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="../css/messages_doctor_mes.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="../css/sweetalert.css?cache=<%=Math.random()%>" >
    <link rel="stylesheet" href="../css/pageCode.css?cache=<%=Math.random()%>" />
    <script src="../js/jquery-1.9.1.min.js"></script>
</head>
<body>
<%@ include file="../header.jsp"%>
<!--内容-->
<div class="containerone">
    <%@ include file="../left_menu.jsp"%>
    <!--右边内容-->
    <div class="right_cont">
        <!--右边导航下面内容-->
        <div >
            <div class="message_hos_news_container" id="content_box">
                <!--左边的渠道-->
                <div class="department_top">
                    <div class="department_top_left department_top_top">
                    <span>
                     <p class="padding-right-min">新闻分类:</p>
                    <select class="news_option_sel" id="news_option_sel" @change="choose_news()" >
                    <template v-for="label in labels">
                    <option  :value="label.id"  v-html="label.name"></option>
                    </template>
                    </select>
                     </span>
                    </div>
                    <!--右边的搜索\添加\批量添加-->
                    <div class="department_top_right ui_line_height">
                        <%
                            if (checkAuth("添加内容管理", input)) {
                        %>
                        <a href="javascript:void(0);"  ><span class="add_btn doctor_add_btn " id='doctor_add_btn'  @click="add_news()">添加</span></a>
                        <%
                            }
                        %>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <!--标题/发表日期/作者/操作-->
                <div class="department_detail" id="doctor_detail">
                    <table class="department_detail_table">
                        <tr class='department_detail_tittle'>
                            <td class='ui_widther'>标题</td>
                            <td class='ui_widthone'>发表日期</td>
                            <td class='ui_widthone'>作者</td>
                            <td class='ui_widthone'>操作</td>
                            <td class='ui_widthone'>是否选为首页轮播</td>
                        </tr>
                        <input type="hidden" name="deptCode" value="">
                        <template v-for="new in news.rank">
                            <tr class="department_detail_c">
                                <td v-html="limitnumber(new.title)"></td>
                                <td v-html="new.time"></td>
                                <td v-html="limitnumber(new.author)"></td>
                                <td class='ui_color'>
                                    <%
                                        if (checkAuth("查看内容管理", input)) {
                                    %>
                                    <span class="mes_doc_edit doctor_add_btn "  @click="see_news(new)" ><a >查看</a></span>
                                    <%
                                        }
                                    %>
                                    <%
                                        if (checkAuth("编辑内容管理", input)) {
                                    %>
                                    <span class="mes_doc_edit doctor_add_btn"  @click="edit_news(new)"><a>编辑</a></span>
                                    <%
                                        }
                                    %>
                                    <%
                                        if (checkAuth("删除内容管理", input)) {
                                    %>
                                    <span class="delete_doc_mes" :id=new.id @click="delete_news(new.id)">删除</span>
                                    <%
                                        }
                                    %>
                                </td>
                                <td>
                                    <%
                                        if (checkAuth("设置轮播", input)) {
                                    %>
                                    <input name="choose_home_picture" type="checkbox"  v-model="new.top"   @change="checkboxOnclick(new)"/>
                                    <%
                                        }
                                    %>
                                </td>
                            </tr>
                        </template>
                    </table>
                </div>
                <div class="split_pages">
                    <div class="record">共<span class="ui_red" v-html='news.count'></span>记录</div>
                    <div class="tcdPageCode holder"></div>
                    <input type="hidden" name="pageCount" value="">
                    <input type="hidden" name="current_page" value="">
                </div>
            </div>
        </div>
    </div>
</div>
<%--点击搜索和选择科室替换--%>

<script src="../js/sweetalert-dev.js"></script>

<script src="../js/jquery.page.js"></script>
<script>
    new Vue({
        el: "#content_box",
        data: {
            labels:[],
            news:[],
        },
        ready: function() {
            var self = this;
            $.ajax({
                type: 'POST',
                url: "content.jsp",
                data: {
                    act: "labels",
                    category:1
                },
                success: function(res) {
                    res = JSON.parse(res);
                    if (res.errcode == 0) {
                        self.labels = res.labels;
                    }
                    $.ajax({
                        type: 'POST',
                        url: "content.jsp",
                        data: {
                            act:"news_list",
                            labelId:self.labels[0].type
                        },
                        success: function(res) {
                            res = JSON.parse(res);
                            if (res.errcode == 0) {
                                self.news = res.data;
                                $(".tcdPageCode")[0].outerHTML = $(".tcdPageCode")[0].outerHTML;
                                $(".tcdPageCode").createPage({
                                    pageCount: self.news.page_count,
                                    current:self.news.current_page,
                                    backFn:function(p){
                                        $.ajax({
                                            type: 'post',
                                            url: "user.jsp",
                                            data: {
                                                act:"news_list",
                                                labelId:self.labels[0].type,
                                                page:p
                                            },
                                            timeout: 3000,
                                            dataType: 'json',
                                            success: function(res) {
                                                if (res.errcode == 0) {
                                                    self.news = res.data;
                                                }
                                            },
                                            error: function(error) {

                                            }
                                        });
                                        return false;//阻止提交
                                    }
                                });
                            }

                        }
                    });

                }
            });


        },
        methods:{
            choose_news:function(){
                var self = this;
                var option=$('.news_option_sel option:selected').val();
                $.ajax({
                    type: 'POST',
                    url: "content.jsp",
                    data: {
                        act:"news_list",
                        labelId:option
                    },
                    success: function(res) {
                        res = JSON.parse(res);
                        if (res.errcode == 0) {
                            self.news = res.data;
                            $(".tcdPageCode")[0].outerHTML = $(".tcdPageCode")[0].outerHTML;
                            $(".tcdPageCode").createPage({
                                pageCount: self.news.page_count,
                                current:self.news.current_page,
                                <%--点击打印页数--%>
                                backFn:function(p){
                                    $.ajax({
                                        type: 'post',
                                        url: "user.jsp",
                                        data: {
                                            act:"news_list",
                                            labelId:option,
                                            page:p
                                        },
                                        timeout: 3000,
                                        dataType: 'json',
                                        success: function(res) {
                                            if (res.errcode == 0) {
                                                self.news = res.data;
                                            }

                                        },
                                        error: function(error) {

                                        }
                                    });
                                    return false;//阻止提交
                                }
                            });
                        }else{
                            self.news = [];
                            $(".tcdPageCode").createPage({
                                pageCount: 0,
                                current:0,
                            });
                        }

                    }
                });

            },
            limitnumber:function(txt) {
                if(txt.length>8){
                    txt = txt.substr(0,8) + '......' ;
                    return txt;
                }
                else{
                    return txt;
                }

            },
            checkboxOnclick:function(checkbox){
                var num=checkbox.top
                if (num == true){
                    $.ajax({
                        type: 'post',
                        url: "content.jsp",
                        data: {
                            act:"set_top",
                            news_id:checkbox.news_id,
                        },
                        timeout: 3000,
                        dataType: 'json',
                        success:function (data) {
                            if(data.errcode==30041){
                                swal({
                                        title: "",
                                        text: "首页轮播最多5张,请取消部分再操作",
                                        type: "warning",
                                        confirmButtonColor: "var(--color)",
                                        confirmButtonText: "确定",
                                    },
                                    function(){
                                        location.reload()
                                    });
                            }else{
                                swal('添加成功');
                            }
                        },
                        error:function (error) {

                        }
                    });

                }else{
                    $.ajax({
                        type: 'post',
                        url:"content.jsp",
                        data: {
                            act:"unset_top",
                            news_id:checkbox.news_id,
                        },
                        timeout: 3000,
                        dataType: 'json',
                        success:function (data) {
                            swal('取消成功');
                        },
                        error:function (error) {

                        }
                    });
                }
            },
            delete_news:function(id){
                swal({
                        title: "您确定要删除吗？",
                        type: "warning",
                        showCancelButton: true,
                        closeOnConfirm: false,
                        confirmButtonText: "是的，我要删除",
                        cancelButtonText:"取消",
                        confirmButtonColor: "#ec6c62"
                    },
                    function(){
                        $.ajax({
                            type: 'post',
                            url: "content.jsp",
                            data: {
                                act:"delete_news",
                                news_id:id,
                            },
                            timeout: 3000,
                            dataType: 'json',
                            success:function (data) {
                                if(data.errcode==0){
                                    self.location.reload()
                                    swal('删除成功')

                                }else{
                                    swal('删除失败')
                                }

                                //console.log(data)
                            },
                            error:function (error) {
                                swal('删除失败')
                            }
                        });
                        return false;//阻止提交
                    }
                );
            },
            add_news: function() {
                var labelId=$('.news_option_sel option:selected').val();
                var option=$('.news_option_sel option:selected').text();
                locationHerf("add_content", {
                    labelId: labelId,
                    option: option
                });
            },
            edit_news: function(item) {
                var labelId=$('.news_option_sel option:selected').val();
                var news_id=item.news_id;
                var option=$('.news_option_sel option:selected').text();
                locationHerf("edit_content", {
                    news_id:news_id,
                    option: option,
                    labelId: labelId
                });
            },
            see_news: function(item) {
                var news_id=item.news_id;
                var option=$('.news_option_sel option:selected').text();
                locationHerf("see_content", {
                    news_id:news_id,
                    option: option
                });
            },


        },

    });
</script>
</body>
</html>
